#!/usr/bin/perl
my %cmd;
@cmd_besfs=("besfs","/besfs","mkdir -p /besfs;mount -t lustre -o rw 192.168.50.181@tcp:/besfs /besfs");
$cmd{besfs}=\@cmd_besfs;
@cmd_bes3fs=("bes3fs","/bes3fs","mkdir -p /bes3fs;mount -t lustre -o rw 192.168.50.159@tcp:/bes3fs /bes3fs");
$cmd{bes3fs}=\@cmd_bes3fs;
@cmd_workfs=("workfs","/workfs","mkdir -p /workfs;mount -t lustre -o ro 192.168.50.138@tcp:/workfs /workfs");
$cmd{workfs}=\@cmd_workfs;
@cmd_scrafs=("scrafs","/scratchfs","mkdir -p /scratchfs;mount -t lustre -o rw 192.168.50.152@tcp:/scrafs /scratchfs");
$cmd{scrafs}=\@cmd_scrafs;
@cmd_pubfs=("pubfs","/publicfs","mkdir -p /publicfs;mount -t lustre -o rw 192.168.50.67@tcp:/pubfs /publicfs");
$cmd{pubfs}=\@cmd_pubfs;
@cmd_dybfs=("dybfs","/dybfs","mkdir -p /dybfs;mount -t lustre -o rw 192.168.50.149@tcp:/dybfs /dybfs");
$cmd{dybfs}=\@cmd_dybfs;
@cmd_junofs=("junofs","/junofs","mkdir -p /junofs;mount -t lustre -o rw 192.168.50.200@tcp:/junofs /junofs");
$cmd{junofs}=\@cmd_junofs;
@cmd_cefs=("cefs","/cefs","mkdir -p /cefs;mount -t lustre -o rw  192.168.50.114@tcp:/cefs /cefs");
$cmd{cefs}=\@cmd_cefs;
@cmd_besfs3=("besfs3","/besfs3","mkdir -p /besfs3;mount -t lustre -o rw 192.168.50.230@tcp:/besfs3 /besfs3");
$cmd{besfs3}=\@cmd_besfs3;
@cmd_acfs=("acfs","/acfs","mkdir -p /acfs;mount -t lustre -o rw 192.168.50.63@tcp:/acfs /acfs");
$cmd{acfs}=\@cmd_acfs;
my $proc=`cat /proc/mounts`;


sub sendmail(){
	my $touser="wangludb\@ihep.ac.cn";
	my $cc="amanda\@ihep.ac.cn";
	my ($mountpoint,$retry,$status)=@_;
	my $host=`hostname`;
	if ($status==0){
		$sub="remount failed of $mountpoint on $host after retry $retry times";
	}else{	
		
		$sub="remount successful of $mountpoint on $host after retry $retry times";
	}
	 `/afs/ihep.ac.cn/soft/common/Python/Python-2.6/bin/python /afs/ihep.ac.cn/soft/common/sysgroup/smtp.pyc -s \"$sub\"  -c $cc $touser `;

	
}
sub remount(){
	my ($mountpoint)=@_;
	my $retry=0;
	my $status=0;
	my $sleeptime=120;
	while(!$status && $retry<3){
		`umount -l "\/$key"`;
		sleep $sleeptime;
		$mountcmd=$cmd{$key}->[2];
		printf "$mountcmd\n";
		system($mountcmd);
		if ($?){
			$retry++;
		}else{
			$status=1;
			&sendmail($key,$retry,$status);
			return 0;
		}
	}
	&sendmail($key,$retry,$status);
	if ($status==0){
		exit -1;
	}
	return 0;
}


for $key(keys %cmd){
	printf "file system check of $key :\n";
        if ($proc =~/$key(\s+)/){
		printf "$key is mounted\n";
	}else{
		printf "$key is not mounted\n";
		&remount ($key);
	}
	printf "\n";
}

